package com.nanhai.buddhist.college.module.collegebase.service.rollchecklog;

import com.nanhai.buddhist.college.framework.common.util.collection.CollectionUtils;
import com.nanhai.buddhist.college.module.collegebase.controller.admin.rollchecklog.vo.RollCheckLogCreateReqVO;
import com.nanhai.buddhist.college.module.collegebase.controller.admin.rollchecklog.vo.RollCheckLogExportReqVO;
import com.nanhai.buddhist.college.module.collegebase.controller.admin.rollchecklog.vo.RollCheckLogPageReqVO;
import com.nanhai.buddhist.college.module.collegebase.controller.admin.rollchecklog.vo.RollCheckLogUpdateReqVO;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import com.nanhai.buddhist.college.module.collegebase.controller.admin.rollchecklog.vo.*;
import com.nanhai.buddhist.college.module.collegebase.dal.dataobject.rollchecklog.RollCheckLogDO;
import com.nanhai.buddhist.college.framework.common.pojo.PageResult;

import com.nanhai.buddhist.college.module.collegebase.convert.rollchecklog.RollCheckLogConvert;
import com.nanhai.buddhist.college.module.collegebase.dal.mysql.rollchecklog.RollCheckLogMapper;

import static com.nanhai.buddhist.college.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.nanhai.buddhist.college.module.collegebase.enums.ErrorCodeConstants.*;

/**
 * 学籍信息审核记录 Service 实现类
 *
 * @author AKai
 */
@Service
@Validated
public class RollCheckLogServiceImpl implements RollCheckLogService {

    @Resource
    private RollCheckLogMapper rollCheckLogMapper;

    @Override
    public String createRollCheckLog(RollCheckLogCreateReqVO createReqVO) {
        // 插入
        RollCheckLogDO rollCheckLog = RollCheckLogConvert.INSTANCE.convert(createReqVO);
        rollCheckLogMapper.insert(rollCheckLog);
        // 返回
        return rollCheckLog.getId();
    }

    @Override
    public void updateRollCheckLog(RollCheckLogUpdateReqVO updateReqVO) {
        // 校验存在
        this.validateRollCheckLogExists(updateReqVO.getId());
        // 更新
        RollCheckLogDO updateObj = RollCheckLogConvert.INSTANCE.convert(updateReqVO);
        rollCheckLogMapper.updateById(updateObj);
    }

    @Override
    public void deleteRollCheckLog(String id) {
        // 校验存在
        this.validateRollCheckLogExists(id);
        // 删除
        rollCheckLogMapper.deleteById(id);
    }

    private void validateRollCheckLogExists(String id) {
        if (rollCheckLogMapper.selectById(id) == null) {
            throw exception(ROLL_CHECK_LOG_NOT_EXISTS);
        }
    }

    @Override
    public RollCheckLogDO getRollCheckLog(String id) {
        return rollCheckLogMapper.selectById(id);
    }

    @Override
    public List<RollCheckLogDO> getRollCheckLogList(Collection<String> ids) {
        return CollectionUtils.isEmpty(ids) ? Collections.emptyList() : rollCheckLogMapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<RollCheckLogDO> getRollCheckLogPage(RollCheckLogPageReqVO pageReqVO) {
        return rollCheckLogMapper.selectPage(pageReqVO);
    }

    @Override
    public List<RollCheckLogDO> getRollCheckLogList(RollCheckLogExportReqVO exportReqVO) {
        return rollCheckLogMapper.selectList(exportReqVO);
    }

}
